package com.fc.v2.controller.gen;

import com.fc.v2.common.base.BaseController;
import com.fc.v2.common.domain.AjaxResult;
import com.fc.v2.common.domain.ResultTable;
import com.fc.v2.model.custom.Tablepar;
import com.fc.v2.model.auto.ApplyScore;
import com.fc.v2.model.wapper.ApplyScoreWapper;
import com.fc.v2.service.ApplyProjectService;
import com.fc.v2.service.ApplyScoreService;
import com.fc.v2.util.BeanUtils;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 申请项目专家评分Controller
 * @ClassName: ApplyScoreController
 * @author Archie
 * @date 2021-11-16 16:40:04
 */
@Api(value = "申请项目专家评分")
@Controller
@RequestMapping("/ApplyScoreController")
public class ApplyScoreController extends BaseController{
	
	private String prefix = "gen/auditApplyExpert";
	
	@Autowired
	private ApplyScoreService applyScoreService;

	@Autowired
	private ApplyProjectService applyProjectService;
	
	
	/**
	 * 申请项目专家评分页面展示
	 * @param model
	 * @return String
	 * @author Archie
	 */
	@ApiOperation(value = "分页跳转", notes = "分页跳转")
	@GetMapping("/view")
	@RequiresPermissions("gen:applyProject:view")
    public String view(ModelMap model)
    {
        return prefix + "/list";
    }
	
	/**
	 * list集合
	 * @param tablepar
	 * @param searchText
	 * @return
	 */
	//@Log(title = "申请项目专家评分", action = "111")
	@ApiOperation(value = "分页跳转", notes = "分页跳转")
	@GetMapping("/list/{proId}")
	@RequiresPermissions("gen:applyProject:list")
	@ResponseBody
	public ResultTable list(Tablepar tablepar,ApplyScore applyScore,@PathVariable("proId") String proId){
		PageInfo<ApplyScore> page=applyScoreService.list(tablepar,applyScore,proId) ;

		//把ApplyScore封装到wrapper中
		List<ApplyScore> list = page.getList();
		List<ApplyScoreWapper> res=new ArrayList<>();
		for(ApplyScore ss:list){
			ApplyScoreWapper wapper = new ApplyScoreWapper();
			BeanUtils.copyBeanProp(wapper,ss);
			String expertName = sysUserService.selectByPrimaryKey(ss.getExpertId()).getNickname();
			wapper.setExpertName(expertName);
			res.add(wapper);
		}

		return pageTable(res,page.getTotal());
//		return pageTable(page.getList(),page.getTotal());
	}

	/**
	 * 专家立项鉴定评分跳转
	 * @param id
	 * @param mmap
	 * @return
	 */
	@ApiOperation(value = "修改跳转", notes = "修改跳转")
	@GetMapping("/applyScore/{id}")
	public String auditScore(@PathVariable("id") String id, ModelMap map)
	{
		map.put("ApplyProject", applyProjectService.selectByPrimaryKey(id));

		return prefix + "/applyScore";
	}

	/**
	 * 专家立项查看评分跳转
	 * @param id
	 * @param mmap
	 * @return
	 */
	@ApiOperation(value = "修改跳转", notes = "修改跳转")
	@GetMapping("/applyScoreCheck/{id}")
	public String auditScoreCheck(@PathVariable("id") String proId, ModelMap map)
	{
//		map.put("ApplyProject", applyProjectService.selectByPrimaryKey(proId));
		map.put("ApplyScore",applyScoreService.selectByExampleCheck(proId));

		return prefix + "/applyScoreCheck";
	}
	
	/**
     * 新增跳转
     */
	@ApiOperation(value = "新增跳转", notes = "新增跳转")
    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
        return prefix + "/add";
    }
	
    /**
     * 新增保存
     * @param 
     * @return
     */
	//@Log(title = "申请项目专家评分新增", action = "111")
	@ApiOperation(value = "新增", notes = "新增")
	@PostMapping("/add/{projectId}")
	@RequiresPermissions("gen:applyProject:add")
	@ResponseBody
	public AjaxResult add(ApplyScore applyScore,@PathVariable("projectId") String projectId){
		int b=applyScoreService.insertSelectiveScore(applyScore,projectId);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}


	
	/**
	 * 申请项目专家评分删除
	 * @param ids
	 * @return
	 */
	//@Log(title = "申请项目专家评分删除", action = "111")
	@ApiOperation(value = "删除", notes = "删除")
	@DeleteMapping("/remove")
	@RequiresPermissions("gen:applyProject:remove")
	@ResponseBody
	public AjaxResult remove(String ids){
		int b=applyScoreService.deleteByPrimaryKey(ids);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}
	
	
	/**
	 * 修改跳转
	 * @param id
	 * @param mmap
	 * @return
	 */
	@ApiOperation(value = "修改跳转", notes = "修改跳转")
	@GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap map)
    {
        map.put("ApplyScore", applyScoreService.selectByPrimaryKey(id));

        return prefix + "/edit";
    }
	
	/**
     * 修改保存
     */
    //@Log(title = "申请项目专家评分修改", action = "111")
	@ApiOperation(value = "修改保存", notes = "修改保存")
    @RequiresPermissions("gen:applyProject:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ApplyScore applyScore)
    {
        return toAjax(applyScoreService.updateByPrimaryKeySelective(applyScore));
    }
    
    
    /**
	 * 修改状态
	 * @param record
	 * @return
	 */
    @PutMapping("/updateVisible")
	@ResponseBody
    public AjaxResult updateVisible(@RequestBody ApplyScore applyScore){
		int i=applyScoreService.updateVisible(applyScore);
		return toAjax(i);
	}

    
    

	
}
